' 
' Copyright (C) 2014 Infinity CCS Ltd (http://www.infinityccs.com/)
' Copyright (C) 2008 Sasa Coh <sasacoh@gmail.com>
'
' This program is free software; you can redistribute it and/or modify
' it under the terms of the GNU General Public License as published by
' the Free Software Foundation; either version 3 of the License, or
' (at your option) any later version.
'
' This program is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
' GNU General Public License for more details.
'
' You should have received a copy of the GNU General Public License
' along with this program.  If not, see <http://www.gnu.org/licenses/>. 
'/


Imports System
Imports System.Collections.Generic
Imports System.Text
Imports Infinity.pjsipNET.Common.Config

Namespace Common


  ''' <summary>
  ''' VoIP protocol stack interface. Defines some common events invoked by VoIP stack and 
  ''' API methods invoked by user.
  ''' </summary>
  Public MustInherit Class IVoipProxy

#Region "Events"

    ' ''' <summary>
    ' ''' User Events. A protected virtual method makes possible to invoke events from derived classes. 
    ' ''' </summary>

    ''' <summary>
    ''' DtmfDigitReceived event trigger by VoIP stack when DTMF is detected 
    ''' </summary>
    Public Event DtmfDigitReceived(callId As Integer, digit As Integer)
    Protected Sub BaseDtmfDigitReceived(callId As Integer, digit As Integer)
      RaiseEvent DtmfDigitReceived(callId, digit)
    End Sub
    '''' <summary>
    '''' MessageWaitingIndication event trigger by VoIP stack when MWI indication arrived 
    '''' </summary>
    Public Event MessageWaitingIndication(mwi As Integer, text As String)
    Protected Sub BaseMessageWaitingIndication(mwi As Integer, text As String)
      RaiseEvent MessageWaitingIndication(mwi, text)
    End Sub

    ''' <summary>
    ''' Notification that call is being replaced.
    ''' </summary>
    Public Event CallReplaced(oldid As Integer, newid As Integer)
    Protected Sub BaseCallReplacedCallback(oldid As Integer, newid As Integer)
      RaiseEvent CallReplaced(oldid, newid)
    End Sub

#End Region 'events

#Region "Properties"

    Private _config As IConfigurator = New NullConfigurator()
    Public Property Config As IConfigurator
      Get
        Return _config
      End Get
      Set(value As IConfigurator)
        _config = value
      End Set
    End Property

    ''' <summary>
    ''' Flag indicating stack initialization status
    ''' </summary>
    Public MustOverride Property IsInitialized As Boolean

#End Region

#Region "Public methods"
    ''' <summary>
    ''' Initialize VoIP stack
    ''' </summary>
    ''' <returns></returns>
    Public MustOverride Function initialize() As Integer

    ''' <summary>
    ''' Shutdown VoIP stack
    ''' </summary>
    ''' <returns></returns>
    Public Overridable Function shutdown() As Integer
      'BaseDtmfDigitReceived = Nothing
      'MessageWaitingIndication = Nothing
      Return 1
    End Function

    ''' <summary>
    ''' Set codec priority
    ''' </summary>
    ''' <param name="item">Codec Name</param>
    ''' <param name="p">priority</param>
    Public MustOverride Sub setCodecPriority(item As String, p As Integer)


    ''' <summary>
    ''' Get number of codecs in list
    ''' </summary>
    ''' <returns>Number of codecs</returns>
    Public MustOverride Function getNoOfCodecs() As Integer

    ''' <summary>
    ''' Get codec by index
    ''' </summary>
    ''' <param name="i">codec index</param>
    ''' <returns>Codec Name</returns>
    Public MustOverride Function getCodec(i As Integer) As String

    ''' <summary>
    ''' Creates an instance of call proxy 
    ''' </summary>
    ''' <returns></returns>
    Public MustOverride Function createCallProxy() As ICallProxy

#End Region

    ''' <summary>
    ''' 
    ''' </summary>
    Public Class NullVoipProxy
      Inherits IVoipProxy
#Region "ICommonProxyInterface Members"

      Public Overrides Function initialize() As Integer
        Return 1
      End Function

      Public Overrides Function shutdown() As Integer
        Return 1
      End Function

      '//public override int registerAccounts()
      '//{
      '//  return 1;
      '//}

      '//public override int addBuddy(string ident, bool presence)
      '//{
      '//  return 1;
      '//}

      '//public override int delBuddy(int buddyId)
      '//{
      '//  return 1;
      '//}

      '//public override int sendMessage(string dest, string message)
      '//{
      '//  return 1;
      '//}

      '//public override int setStatus(int accId, EUserStatus presence_state)
      '//{
      '//  return 1;
      '//}

      Public Overrides Sub setCodecPriority(item As String, p As Integer)

      End Sub

      Public Overrides Function getNoOfCodecs() As Integer
        Return 0
      End Function

      Public Overrides Function getCodec(i As Integer) As String
        Return ""
      End Function

      Public Overrides Property IsInitialized As Boolean
        Get
          Return False
        End Get
        Set(value As Boolean)

        End Set
      End Property

      Public Overrides Function createCallProxy() As ICallProxy
        Return New ICallProxy.NullCallProxy()
      End Function
#End Region '  Null Pattern

    End Class
  End Class

End Namespace